custom_logging_functions module
Module containing functions for the custom logging functionality. The functions here make it possible for the user to define binaryc output logs on runtime
TODO: we can extend this codebase to handle building custom ensemble functions as well so we can control binary_c with the ensembles as well
- binarycpython.utils.custom_logging_functions.autogen_C_logging_code(logging_dict, verbosity=0)[source]
- Function that auto-generates PRINTF statements for binaryc. Input is a dictionary where the key is the header of that logging line and items which are lists of parameters that will be put in that logging line - The list elements are all appended to ‘stardata->’ in the auto-generated code. - Example - Input dictionary should look like this: - {'MY_STELLAR_DATA': [ 'model.time', 'star[0].mass', 'model.probability', 'model.dt' ] } - Parameters
- logging_dict ( - dict) – Dictionary containing lists of parameters that binary_c has to output. The keys are used by binary_c as start of the sentence.
- verbose – Level of verbosity. Defaults to zero if not set explicitly. 
 
- Return type
- Optional[- str]
- Returns
- string containing C printf statement built to output the parameters given as input. 
 
- binarycpython.utils.custom_logging_functions.binary_c_ensemble_code(code, verbosity=0)[source]
- Function to construct the code to construct the custom ensemble function - Parameters
- code ( - str) – Exact c-statement to output information in binary_c. Can be wrapped in logical statements.
- verbosity ( - int) – Level of verbosity. Defaults to zero if not set explicitly.
 
- Return type
- str
- Returns
- string containing the custom ensemble code. This includes all the includes and other definitions. This code will be used as the shared library 
 
- binarycpython.utils.custom_logging_functions.binary_c_log_code(code, verbosity=0)[source]
- Function to construct the code to construct the custom logging function - Example - Code to log and terminate evolution when the primary star becomes a NS: - if(stardata->star[0].stellar_type>=NS) { if (stardata->model.time < stardata->model.max_evolution_time) { Printf("EXAMPLE_LOG_CO %30.12e %g %g %g %g %d %d\n", // stardata->model.time, // 1 stardata->star[0].mass, //2 stardata->previous_stardata->star[0].mass, //3 stardata->star[0].radius, //4 stardata->previous_stardata->star[0].radius, //5 stardata->star[0].stellar_type, //6 stardata->previous_stardata->star[0].stellar_type //7 ); }; /* Kill the simulation to save time */ stardata->model.max_evolution_time = stardata->model.time - stardata->model.dtm; }; - Parameters
- code ( - str) – Exact c-statement to output information in binary_c. Can be wrapped in logical statements.
- verbosity ( - int) – Level of verbosity. Defaults to zero if not set explicitly.
 
- Return type
- str
- Returns
- string containing the custom logging code. This includes all the includes and other definitions. This code will be used as the shared library 
 
- binarycpython.utils.custom_logging_functions.binary_c_write_code(code, filename, verbosity=0)[source]
- Function to write the generated logging code to a file - Parameters
- code ( - str) – string containing the custom logging code to write to a file.
- filename ( - str) – target filename.
- verbosity ( - int) – Level of verbosity. Defaults to zero if not set explicitly.
 
- Return type
- None
 
- Function to write the custom logging code to a file and then compile it. - TODO: consider returning a status - Parameters
- sourcefile_name ( - str) – name of the file that will contain the code
- outfile_name ( - str) – name of the file that will be the shared library
- verbosity ( - int) – Level of verbosity. Defaults to zero if not set explicitly.
 
- Return type
- None
 
- binarycpython.utils.custom_logging_functions.create_and_load_ensemble_function(custom_ensemble_code, verbosity=0, custom_tmp_dir=None)[source]
- Function to automatically compile the shared library with the given custom ensemble code and load it with ctypes. - This function is more or less the main function of this module and unless you know what you’re doing with the other functions I recommend using this in function in combination with a function that generates the exact code (like - binary_c_ensemble_code())- Parameters
- custom_ensemble_code ( - str) – string containing the custom logging code
- verbosity ( - int) – Level of verbosity. Defaults to zero if not set explicitly.
 
- Return type
- Tuple[- int,- str]
- Returns
- memory address of the custom ensemble function in a capsule. 
 
- binarycpython.utils.custom_logging_functions.create_and_load_logging_function(custom_logging_code, verbosity=0, custom_tmp_dir=None)[source]
- Function to automatically compile the shared library with the given custom logging code and load it with ctypes. - This function is more or less the main function of this module and unless you know what you’re doing with the other functions I recommend using this in function in combination with a function that generates the exact code (like - binary_c_log_code())- Parameters
- custom_logging_code ( - str) – string containing the custom logging code
- verbosity ( - int) – Level of verbosity. Defaults to zero if not set explicitly.
 
- Return type
- Tuple[- int,- str]
- Returns
- memory address of the custom logging function 
 
- binarycpython.utils.custom_logging_functions.from_binary_c_config(config_file, flag)[source]
- Function to run the - binaryc_configcommand with flags- Parameters
- config_file ( - str) –- binary_c-configfilepath. TODO: change the name of this
- flag ( - str) – flag used in the- binary_c-configcall.
 
- Return type
- str
- Returns
- returns the result of - <binary_c-config> <flag>
 
- binarycpython.utils.custom_logging_functions.get_dynamic_library_file_extension()[source]
- Function to find the correct file extension - It will return .so except for exceptions based on platform.platform() 
- binarycpython.utils.custom_logging_functions.return_compilation_dict(verbosity=0)[source]
- Function to build the compile command for the shared library - Inspired by binary_c_inline_config command in Perl - TODO: this function still has some cleaning up to do w.r.t. default values for the compile command # https://developers.redhat.com/blog/2018/03/21/compiler-and-linker-flags-gcc/ - Parameters
- verbosity ( - int) – Level of verbosity. Defaults to zero if not set explicitly.
- Return type
- dict
- Returns
- string containing the command to build the shared library